package mars.ns.listeners

import mars.ns.core.Node
import mars.ns.core.Network
import mars.ns.core.LinkType
import mars.ns.Simulation


class EventExecutionListener[T <: Node](private val simulation : Simulation[T]) extends SimulationListener[T] {
	private var events : List[(T,(T => Unit))] = List[(T,(T => Unit))]()

	/**
	 * Add an event to the event executionListener
	 */
	def addEvent(node : T,event : (T => Unit)){
	    if(node != null && event != null)
	    	events ::= (node,event)
	}
	
    def update(net: Network[T], iterator: Int){
        events.foreach{ case (node,event) => event(node);simulation.notifyNodeChanged(node) }
        events = List[(T,(T => Unit))]()
    }
	
	def edgeAdded(from : T, to:T, lType :LinkType) {}
	def nodeChanged(node :T){}
}